package com.rowline.admin.module.study.variable;

/**
 * ClassName:Variable
 * Created by 245167
 * on 2017/10/19  19:22
 * description:
 */
public class Variable {

    private int n;

    public static void main(String[] args) {
        int n2;
        //System.out.println("n2 = " + n2);

        /**
         * Char是无符号型的，可以表示一个整数，不能表示负数；
         * 而byte是有符号型的，可以表示-128—127 的数
         */

        char a = (char)-1;
        System.out.println(a);
        System.out.println("=====================================");

        byte b1 = 1;
        byte b2 = -1;
        byte b3 = 127;
        byte b4 = -128;
        System.out.println("b1 = " + b1);
        System.out.println("b2 = " + b2);
        System.out.println("b3 = " + b3);
        System.out.println("b4 = " + b4);

        System.out.println("=====================================");

        String msg = "中国abc";
        System.out.println(msg);
        int len = msg.getBytes().length;//按操作系统默认编码来编码
        // 由此看出来，系统现在的编码方式是UTF-8
        System.out.println(len);
        try{
            len = msg.getBytes("GB2312").length;//输出7
            System.out.println("GB2312: "+len);
            len = msg.getBytes("GBK").length;//输出7
            System.out.println("GBK: "+len);
//            len = msg.getBytes("GB18030").length;//输出7, 2*2+3,一个汉字占2字节,一个英文字母一个字节
//            System.out.println("GB18030: "+len);
            len = msg.getBytes("UTF-8").length;//输出9, 2*3+3=9,一个汉字占3字节,一个英文字母一个字节.
            System.out.println("UTF-8: "+len);
            len = msg.getBytes("UTF-16").length;//输出12,2*3+6=12
            System.out.println("UTF-16: "+len);
            len = msg.getBytes("UTF-32").length;//输出20,2*4+12=20
            System.out.println("UTF-32: "+len);
            len = msg.getBytes("Unicode").length;//输出12,2*3+6=12
            System.out.println("Unicode: "+len);
        } catch ( java.io.UnsupportedEncodingException e) {
            System.out.println(e.getMessage().toString());
        }

    }
}
